home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F17540_dates0.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-09-23  |  1.4 KB  |  45 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- ============================================================
  3. Example for sorting dates in the ISO format yyyy-mm-dd
  4. Use with: Dates0.xml
  5. Notes:-
  6. 1) The hyphen separator is optional
  7. ================================================================= -->
  8. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  9. <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
  10. <!-- define variable that is used as the separator in dates -->
  11. <!-- (this saves having to re-work the code for different separators -->
  12. <xsl:variable name="date-sep" select="'/'"/>
  13. <xsl:template match="/">
  14.     <html><body>
  15.     <table border="1">
  16.         <tr>
  17.             <th>Sorted Position</th>
  18.             <th>Sort value</th>
  19.             <th>Original date value</th>
  20.             <th>Original position</th>
  21.         </tr>
  22.         <xsl:for-each select="/root/item">
  23.             <!-- sort algorithm -->
  24.             <xsl:sort select="translate(@date,'-','')" data-type="number"/>
  25.             <tr>
  26.                 <td>
  27.                     <xsl:value-of select="position()"/>
  28.                 </td>
  29.                 <td>
  30.                     <!-- the numeric date -->
  31.                     <xsl:value-of select="translate(@date,'-','')"/>
  32.                 </td>
  33.                 <td>
  34.                     <xsl:value-of select="@date"/>
  35.                 </td>
  36.                 <td>
  37.                     <!-- show the order of the element in the original xml -->
  38.                     <xsl:value-of select="count(preceding-sibling::item)+1"/>
  39.                 </td>
  40.             </tr>
  41.         </xsl:for-each>
  42.     </table>
  43.     </body></html>
  44. </xsl:template>
  45. </xsl:stylesheet>